import 'package:get/get.dart';
import 'package:kkhousekeep/config/constant.dart';

import '../../../../models/repair_order_result_entity.dart';
import '../../../../net/home_repair_connect.dart';
import '../../../public/take_picture_screen.dart';

class RepairResultController extends GetxController {
  late HomeRepairConnect connect;

  var fatalType = ''.obs;
  var repairStandard = ''.obs;
  var result = ''.obs;
  var cause = ''.obs;
  var propose = ''.obs;
  var pics = <String>[].obs;

  var orderId = -1;

  @override
  void onInit() {
    orderId = Get.arguments[ArgumentKey.orderId] ?? orderId;
    connect = Get.find<HomeRepairConnect>();
    _loadNetworkData();
    super.onInit();
  }

  void performClickImageItem(String path) {
    Get.to(() => DisplayPictureScreen(
          imagePath: path,
          isShowRetake: false,
        ));
  }

  void _loadNetworkData() async {
    RepairOrderResultObj resultEntity =
        await connect.getRepairOrderResult(orderId: orderId);
    fatalType.value = resultEntity.fatalType;
    repairStandard.value = resultEntity.repairStandard;
    result.value = resultEntity.result;
    cause.value = resultEntity.cause;
    propose.value = resultEntity.propose;
    pics.value = resultEntity.pics;
  }
}
